var jsonList = {};
jsonList.state = 3;
var page = 1;
var rows = 10;
$(function (){
    //获取文章列表详情
    $(document).on("click", ".arc_open", function () {
        var id = $(this).attr("arid");
        //console.log(id);
        window.location.href="./fabu_wz.html?id=" + id;
    })
    //撤销发布
    $(".c_xiao").on("click", function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要撤销发布吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/release/special/cancel?ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        console.log(res, 333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('撤销发布失败');
                        }
                    }
                })
            })
        } else {
            zeroModal.alert('请选择至少一条专题发布');
        }
    })
    //获取频道列表
    var jsonl={};
    var result = JSON.stringify(jsonl);
    $.ajax({
        url: baseNews + "/api/data/channel/list?page=1&rows=200", 
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res,6666);
            if (res.code == 0) {
                var obj = $(".yfb_ztp");
                $(res.data.list).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.cname + "</option>");
               })
            }
        }
    })
    //搜索
    $(".in_ztai").change(function () {
        jsonList.cid = $(this).val();
    })
    $(".in_sou").click(function (){
        jsonList.state = 3;
        var ztid = $(".in_zt").val();//专题id
        var zname = $(".in_mc").val();//专题名称
      
        if (ztid!=""){
            jsonList.id = ztid;
        }
        if (zname!=""){
            jsonList.title=zname
        }
        console.log(jsonList,3333)
        getList();
    })
})
getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/common/special/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".yfb_list").empty();
                $(list).each(function (index, key) {
                    var state = key.state;//文章的状态
                    var newState = "";//文章的
                    if (state == 0) {
                        newState = "";
                    }
                    if (state == 1) {
                        newState = "待审核";
                    }
                    if (state == 2) {
                        newState = "待发布";
                    }
                    if (state == 3) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "有更新";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    html += `<tr>
                                <th><input  class="arc_isc"  type="checkbox"  oid="${key.id}"/></th>
                                <th >${key.id}</th>
                                <th class="b_t">${key.title}</th>
                                <th>${newState}</th>
                                <th>${key.cname }</th>
                                <th>${key.articles }</th>
                                <th>${key.createtime }</th>
                                <th style="color:blue;cursor: pointer;" class="arc_open" arid="${key.id}">查看/编辑文章</th>
                                <th></th>
                            </tr>`;
                })
                $(".yfb_list").append(html);
            }
        }

    })
    //分页

}